home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / util / time / backclock.lha / BackClock / sources / main.c < prev    next >
C/C++ Source or Header  |  1998-02-08  |  3KB  |  98 lines

  1. /*****************************************************************************
  2.  *
  3.  * Nom            : main.c
  4.  *
  5.  * version        : $VER: main.c 1.1 (06.02.98)
  6.  *
  7.  * History
  8.  * V1.0: initial version
  9.  * V1.1: can be started from WB with Tooltypes
  10.  *       added notifyintuition routines to close the window automatically
  11.  * v1.2: window can initialy sized thanks to tooltypes
  12.  *       window goes to back every seconds
  13.  *       first public release
  14.  *****************************************************************************
  15.  */
  16. #include <intuition/intuition.h>
  17. #include <dos/dos.h>
  18. #include <exec/ports.h>
  19. #include <exec/libraries.h>
  20. #include <exec/memory.h>
  21. #include <workbench/startup.h>
  22.  
  23. #include <proto/intuition.h>
  24. #include <proto/exec.h>
  25. #include "utils.h"
  26. /* bump revision
  27.  */
  28. char  * nosense = "\0$VER: " TITLE " (06.02.98)" ;
  29. struct Library * IconBase ;
  30. void main() {
  31.   /* lance du CLI
  32.    */
  33.   idWin * myprj ;
  34.   if (exists() == FALSE) {
  35.     if ((myprj = init(NULL)) != NULL) {
  36.       //writeDate(myprj) ;
  37.       processwin(myprj) ;
  38.     }
  39.     close(myprj) ;
  40.   }
  41.  
  42. }
  43. void wbmain(struct WBStartup * wbmess) {
  44.   /* lance du WB
  45.    */
  46.   
  47.   idWin * myprj ;
  48.   if (exists() == FALSE ) {
  49.     if ((IconBase = OpenLibrary("icon.library", 37)) != NULL) {
  50.       if ((myprj = init(wbmess->sm_ArgList)) != NULL) {
  51.         processwin(myprj) ;
  52.       }
  53.       close(myprj) ;
  54.       CloseLibrary(IconBase) ;
  55.     }
  56.   }
  57. }
  58. int exists() {
  59.   int ret = FALSE ;
  60.   struct EasyStruct EZ ;
  61.   struct MsgPort * oldPort ;
  62.   struct MsgPort * replyPort ; 
  63.   struct backMsg * msg ;
  64.  
  65.   Forbid() ;
  66.   oldPort = FindPort("backclock") ;
  67.   Permit() ;
  68.   
  69.   if (oldPort) {
  70.     /* le programme est deja lance
  71.      */
  72.     EZ.es_StructSize   = sizeof(struct EasyStruct) ;
  73.     EZ.es_Flags        = NULL ;
  74.     EZ.es_Title        = TITLE ;
  75.     EZ.es_TextFormat   = "You are about to quit BackClock\nAre you sure ?" ;
  76.     EZ.es_GadgetFormat = "Quit|Cancel" ;
  77.     if (EasyRequestArgs(NULL, &EZ, NULL, NULL) == 1) {
  78.       /* utilisateur choisit quit
  79.        */  
  80.       if ((replyPort = CreateMsgPort()) != NULL) {
  81.         if ((msg = AllocVec(sizeof(struct backMsg), MEMF_PUBLIC)) != NULL) {
  82.           msg->execmsg.mn_Node.ln_Type = NT_MESSAGE ;
  83.           msg->execmsg.mn_Length       = sizeof(struct backMsg) ;
  84.           msg->execmsg.mn_ReplyPort    = replyPort ;
  85.           PutMsg(oldPort, (struct Message*)msg) ;
  86.           WaitPort(replyPort) ;
  87.           DeleteMsgPort(replyPort) ;
  88.           FreeVec(msg) ;
  89.           ret=OK ;
  90.         }else {
  91.           ret=ERRORNOMEM ;
  92.           DeleteMsgPort(replyPort) ;
  93.         }
  94.       }else ret=ERRORNOMEM ;
  95.     }else ret = OK ;
  96.   }
  97.   return(ret) ;
  98. }